﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Degrade
{
    public partial class Input_Password : Form
    {
        public Input_Password(string password)
        {
            InitializeComponent();
            this.Password = password;
        }
        private string Password;
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get; set; } = false;
        /// <summary>
        /// 成功后的操作
        /// </summary>
        public Action SuccessAction { get; set; }

        private void button1_Click(object sender, EventArgs e)
        {
            if (Password.Trim().ToLower()==textBox1.Text.Trim().ToLower())
            {
                IsSuccess = true;
                this.Close();
                SuccessAction?.Invoke();
            }
            else
            {
                DialogResult result = MessageBox.Show("密码错误！", "密码错误", MessageBoxButtons.OK);
                if (result == DialogResult.OK)
                {
                    this.Close();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(this, null);
            }
        }
    }
}
